import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../components/Home.vue'
//let Hot = () => import('../components/Hot.vue')
let News = () => import('../components/News.vue')
let Mine = () => import('../components/Mine.vue')
let Sports = () => import('../components/Sports.vue')
let Film = () => import('../components/Film.vue')
let Military = () => import('../components/Military.vue')
Vue.use(VueRouter)
//创建路由对象集合
let routes = [
  {
    path: '/home',
    name: 'Home',
    component: Home,
  },
  {
    path: '/mine',
    name: 'Mine',
    component: Mine,
  },
  {
    path: '/hot',
    // 重定向到mine路由
    redirect: '/mine',
  },
  {
    path: '/news',
    name: 'News',
    component: News,
    redirect: '/news/military',
    //二级路由
    children: [
      {
        path: 'sports',
        name: 'Sports',
        component: Sports,
      },
      {
        path: 'film',
        name: 'Film',
        component: Film,
      },
      {
        path: 'military',
        name: 'Military',
        component: Military,
      },
    ],
  },
]
//Military，Sports, Film
let router = new VueRouter({ routes })

//避免重复点击当前页面的路径提示异常，不影响程序的正常执行
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch((err) => err)
}
export default router
